//
//  NetWorkTool.swift
//  SinaWeiBo
//
//  Created by dengchen on 15/11/16.
//  Copyright © 2015年 name. All rights reserved.
//

import AFNetworking
import UIKit
import SVProgressHUD

//App接口调试信息 一般接口分为测试接口和线上接口
//private let baseURLString = "https://api.weibo.com/"

private let baseURLString = "https://api.weibo.com/"

class NetWorkTool: AFHTTPSessionManager {
    
    
    static let shared:NetWorkTool = {
       let tool = NetWorkTool(baseURL:NSURL(string:baseURLString))
        tool.responseSerializer.acceptableContentTypes?.insert("text/plain")
        return tool
    }()
    
    
    func requestData(HTTPMethod:String, URLString: String, parameters: AnyObject, success: (result:AnyObject) -> Void,failure: (error:NSError) -> Void)
    {
        
        SVProgressHUD.showWithStatus(MessageTipLoading)
        
        dataTaskWithHTTPMethod(HTTPMethod, URLString: URLString, parameters:parameters, success:{(_, res) -> Void in
            
            success(result: res)
            
            SVProgressHUD.dismiss()

            }) { (_, error) -> Void in
                
            failure(error: error)
                
            SVProgressHUD.dismiss()
            SVProgressHUD.showErrorWithStatus(MessageTipError)
                print(error)
                
        }.resume()
        
    }
    
    
    
    
    
    
}
